﻿#ifndef DOWNLOAD_H
#define DOWNLOAD_H

#include <QObject>
#include <QUrl>
#include <QFile>
#include <QFileInfo>
#include <QtNetwork>
#include <QDebug>
#include <openssl/sha.h>
#include "DataType/PortStruct.h"

class Download : public QObject
{
    Q_OBJECT
public:
    explicit Download(QObject *parent = 0);

    void setParam(const PortStruct &source,const quint8 &fileType, const QString &url, const QByteArray &sha, const QString &path);
    void start();
    bool CheckFileName(QString Type,QString FileName);
//    enum XmlFileName
//    {

//        basicxml            = "Basic",
//        CustomSceneList      ="CustomSceneList",
//        ZigbeeList          = "ZigbeeList",
//        Zigbee3List         = "Zigbee3List",
//        Zigbee3InfraredXml  = "Zigbee3InfraredXml",
//        AutomaticList       = "AutomaticList",
//        ElevatorIP          = "ElevatorIP",
//        IPList              = "IPList",
//        ModbusList          ="ModbusList",
//        OtherEquipment      ="OtherEquipment",
//        RangeResolveList    ="RangeResolveList",
//        SavePoint           ="SavePoint",
//        SceneList           ="SceneList",
//        TempControl         ="TempControl",
//        UserList            ="UserList",
//    };
    enum xml{base,bss,ba};


private:
    PortStruct m_source;
    quint8  m_fileType;
    QString m_url;
    QByteArray m_sha;
    QString m_path;
    QString m_fileName;
    QFile  *m_file;
    QNetworkAccessManager *m_http;
    QNetworkReply *m_reply;

signals:
    void downloadFinishedSignal(PortStruct source,bool isSucceed, quint8 fileType, QString path);
private slots:
    void readyReadSlot();
    void finishedSlot();

};

#endif // DOWNLOAD_H
